import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * model - 单点登录配置
 * @date: 2019-6-27
 */
import { getResponse, createPagination, parseParameters } from 'utils/utils';
import { queryMapIdpValue, queryIdpValue } from 'cpaas-front/lib/services/api';
import { queryConfig, createConfig as _createConfig, deleteConfig as _deleteConfig, editConfig as _editConfig, getConfigDetail as _getConfigDetail, fetchMessageDetail as _fetchMessageDetail } from "../services/ssoConfigService";
import { fetchTemplateAssign, fetchPortalAssignAssignable, templateAssignCreate as _templateAssignCreate, templateAssignDefault as _templateAssignDefault, templateAssignDelete as _templateAssignDelete } from "../services/templateAssignService";
import { deleteTemplateConfigs as _deleteTemplateConfigs, fetchTemplateConfigsList, createTemplateConfigs as _createTemplateConfigs, updateTemplateConfigs as _updateTemplateConfigs, getTemplateConfigsDetail as _getTemplateConfigsDetail } from "../services/templateConfigService";
export default {
  namespace: 'ssoConfig',
  state: {
    pagination: {},
    // 分页参数
    ssoConfigList: [],
    // 配置列表
    ssoConfigDetail: {},
    // 配置详情
    typeList: [],
    // 单点登录类别
    templateAssignList: [],
    // 分配模板列表
    templateConfigList: [],
    // 模板配置列表
    templateConfigsTypeList: [],
    // 配置类型列表
    templateConfigsDetail: {},
    // 查询明细列表
    assignableList: [],
    // 可分配模板列表
    templateConfigPagination: {},
    // 模板配置列表分页
    assignablePagination: {},
    // 可分配模板列表分页
    messageDetail: {}
  },
  effects: {
    // 获取初始化数据
    init: /*#__PURE__*/_regeneratorRuntime.mark(function init(_ref, _ref2) {
      var payload, call, put, lovCodes, res, typeList;
      return _regeneratorRuntime.wrap(function init$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call, put = _ref2.put;
              lovCodes = payload.lovCodes;
              _context.t0 = getResponse;
              _context.next = 6;
              return call(queryMapIdpValue, lovCodes);

            case 6:
              _context.t1 = _context.sent;
              res = (0, _context.t0)(_context.t1);
              typeList = res.typeList;
              _context.next = 11;
              return put({
                type: 'updateState',
                payload: {
                  typeList: typeList
                }
              });

            case 11:
            case "end":
              return _context.stop();
          }
        }
      }, init);
    }),
    // 获取初始化数据
    initConfigType: /*#__PURE__*/_regeneratorRuntime.mark(function initConfigType(_, _ref3) {
      var call, put, templateConfigsTypeList;
      return _regeneratorRuntime.wrap(function initConfigType$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              call = _ref3.call, put = _ref3.put;
              _context2.t0 = getResponse;
              _context2.next = 4;
              return call(queryIdpValue, 'CPFM.CONFIG_TYPE_CODE');

            case 4:
              _context2.t1 = _context2.sent;
              templateConfigsTypeList = (0, _context2.t0)(_context2.t1);
              _context2.next = 8;
              return put({
                type: 'updateState',
                payload: {
                  templateConfigsTypeList: templateConfigsTypeList
                }
              });

            case 8:
            case "end":
              return _context2.stop();
          }
        }
      }, initConfigType);
    }),
    // 获取列表
    fetchConfigList: /*#__PURE__*/_regeneratorRuntime.mark(function fetchConfigList(_ref4, _ref5) {
      var payload, put, call, res, data;
      return _regeneratorRuntime.wrap(function fetchConfigList$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref4.payload;
              put = _ref5.put, call = _ref5.call;
              _context3.next = 4;
              return call(queryConfig, parseParameters(payload));

            case 4:
              res = _context3.sent;
              data = getResponse(res);

              if (!data) {
                _context3.next = 9;
                break;
              }

              _context3.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  ssoConfigList: data.content,
                  pagination: createPagination(data)
                }
              });

            case 9:
            case "end":
              return _context3.stop();
          }
        }
      }, fetchConfigList);
    }),
    // 获取列表明细
    getConfigDetail: /*#__PURE__*/_regeneratorRuntime.mark(function getConfigDetail(_ref6, _ref7) {
      var payload, put, call, res, data;
      return _regeneratorRuntime.wrap(function getConfigDetail$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref6.payload;
              put = _ref7.put, call = _ref7.call;
              _context4.next = 4;
              return call(_getConfigDetail, payload);

            case 4:
              res = _context4.sent;
              data = getResponse(res);

              if (!data) {
                _context4.next = 9;
                break;
              }

              _context4.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  ssoConfigDetail: data
                }
              });

            case 9:
              return _context4.abrupt("return", data);

            case 10:
            case "end":
              return _context4.stop();
          }
        }
      }, getConfigDetail);
    }),
    // 获取分配模板列表
    getTemplateAssignList: /*#__PURE__*/_regeneratorRuntime.mark(function getTemplateAssignList(_ref8, _ref9) {
      var payload, put, call, res, data;
      return _regeneratorRuntime.wrap(function getTemplateAssignList$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              payload = _ref8.payload;
              put = _ref9.put, call = _ref9.call;
              _context5.next = 4;
              return call(fetchTemplateAssign, payload);

            case 4:
              res = _context5.sent;
              data = getResponse(res);

              if (!data) {
                _context5.next = 9;
                break;
              }

              _context5.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  templateAssignList: data
                }
              });

            case 9:
              return _context5.abrupt("return", data);

            case 10:
            case "end":
              return _context5.stop();
          }
        }
      }, getTemplateAssignList);
    }),
    // 获取模板分配提示信息详情
    fetchMessageDetail: /*#__PURE__*/_regeneratorRuntime.mark(function fetchMessageDetail(_ref10, _ref11) {
      var payload, put, call, res, data;
      return _regeneratorRuntime.wrap(function fetchMessageDetail$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              payload = _ref10.payload;
              put = _ref11.put, call = _ref11.call;
              _context6.next = 4;
              return call(_fetchMessageDetail, payload);

            case 4:
              res = _context6.sent;
              data = getResponse(res);

              if (!data) {
                _context6.next = 9;
                break;
              }

              _context6.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  messageDetail: data
                }
              });

            case 9:
            case "end":
              return _context6.stop();
          }
        }
      }, fetchMessageDetail);
    }),
    // 获取模板配置列表
    getTemplateConfigList: /*#__PURE__*/_regeneratorRuntime.mark(function getTemplateConfigList(_ref12, _ref13) {
      var payload, put, call, res, data;
      return _regeneratorRuntime.wrap(function getTemplateConfigList$(_context7) {
        while (1) {
          switch (_context7.prev = _context7.next) {
            case 0:
              payload = _ref12.payload;
              put = _ref13.put, call = _ref13.call;
              _context7.next = 4;
              return call(fetchTemplateConfigsList, payload);

            case 4:
              res = _context7.sent;
              data = getResponse(res);

              if (!data) {
                _context7.next = 9;
                break;
              }

              _context7.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  templateConfigList: data.content,
                  templateConfigPagination: createPagination(data)
                }
              });

            case 9:
              return _context7.abrupt("return", data);

            case 10:
            case "end":
              return _context7.stop();
          }
        }
      }, getTemplateConfigList);
    }),
    // 获取可分配模板列表
    getAssignableList: /*#__PURE__*/_regeneratorRuntime.mark(function getAssignableList(_ref14, _ref15) {
      var payload, put, call, res, data;
      return _regeneratorRuntime.wrap(function getAssignableList$(_context8) {
        while (1) {
          switch (_context8.prev = _context8.next) {
            case 0:
              payload = _ref14.payload;
              put = _ref15.put, call = _ref15.call;
              _context8.next = 4;
              return call(fetchPortalAssignAssignable, payload);

            case 4:
              res = _context8.sent;
              data = getResponse(res);

              if (!data) {
                _context8.next = 9;
                break;
              }

              _context8.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  assignableList: data.content,
                  assignablePagination: createPagination(data)
                }
              });

            case 9:
              return _context8.abrupt("return", data);

            case 10:
            case "end":
              return _context8.stop();
          }
        }
      }, getAssignableList);
    }),
    // 设置默认模板
    templateAssignDefault: /*#__PURE__*/_regeneratorRuntime.mark(function templateAssignDefault(_ref16, _ref17) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function templateAssignDefault$(_context9) {
        while (1) {
          switch (_context9.prev = _context9.next) {
            case 0:
              payload = _ref16.payload;
              call = _ref17.call;
              _context9.next = 4;
              return call(_templateAssignDefault, payload);

            case 4:
              res = _context9.sent;
              return _context9.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context9.stop();
          }
        }
      }, templateAssignDefault);
    }),
    // 批量分配模板
    templateAssignCreate: /*#__PURE__*/_regeneratorRuntime.mark(function templateAssignCreate(_ref18, _ref19) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function templateAssignCreate$(_context10) {
        while (1) {
          switch (_context10.prev = _context10.next) {
            case 0:
              payload = _ref18.payload;
              call = _ref19.call;
              _context10.next = 4;
              return call(_templateAssignCreate, payload);

            case 4:
              res = _context10.sent;
              return _context10.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context10.stop();
          }
        }
      }, templateAssignCreate);
    }),
    // 批量删除模板
    templateAssignDelete: /*#__PURE__*/_regeneratorRuntime.mark(function templateAssignDelete(_ref20, _ref21) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function templateAssignDelete$(_context11) {
        while (1) {
          switch (_context11.prev = _context11.next) {
            case 0:
              payload = _ref20.payload;
              call = _ref21.call;
              _context11.next = 4;
              return call(_templateAssignDelete, payload);

            case 4:
              res = _context11.sent;
              return _context11.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context11.stop();
          }
        }
      }, templateAssignDelete);
    }),
    // 新建配置
    createConfig: /*#__PURE__*/_regeneratorRuntime.mark(function createConfig(_ref22, _ref23) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function createConfig$(_context12) {
        while (1) {
          switch (_context12.prev = _context12.next) {
            case 0:
              payload = _ref22.payload;
              call = _ref23.call;
              _context12.next = 4;
              return call(_createConfig, payload);

            case 4:
              res = _context12.sent;
              return _context12.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context12.stop();
          }
        }
      }, createConfig);
    }),
    // 编辑配置
    editConfig: /*#__PURE__*/_regeneratorRuntime.mark(function editConfig(_ref24, _ref25) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function editConfig$(_context13) {
        while (1) {
          switch (_context13.prev = _context13.next) {
            case 0:
              payload = _ref24.payload;
              call = _ref25.call;
              _context13.next = 4;
              return call(_editConfig, payload);

            case 4:
              res = _context13.sent;
              return _context13.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context13.stop();
          }
        }
      }, editConfig);
    }),
    // 删除配置
    deleteConfig: /*#__PURE__*/_regeneratorRuntime.mark(function deleteConfig(_ref26, _ref27) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function deleteConfig$(_context14) {
        while (1) {
          switch (_context14.prev = _context14.next) {
            case 0:
              payload = _ref26.payload;
              call = _ref27.call;
              _context14.next = 4;
              return call(_deleteConfig, payload);

            case 4:
              res = _context14.sent;
              return _context14.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context14.stop();
          }
        }
      }, deleteConfig);
    }),
    // 查询模板管理详情
    getTemplateConfigsDetail: /*#__PURE__*/_regeneratorRuntime.mark(function getTemplateConfigsDetail(_ref28, _ref29) {
      var payload, call, put, res, list;
      return _regeneratorRuntime.wrap(function getTemplateConfigsDetail$(_context15) {
        while (1) {
          switch (_context15.prev = _context15.next) {
            case 0:
              payload = _ref28.payload;
              call = _ref29.call, put = _ref29.put;
              _context15.next = 4;
              return call(_getTemplateConfigsDetail, payload);

            case 4:
              res = _context15.sent;
              list = getResponse(res);

              if (!list) {
                _context15.next = 9;
                break;
              }

              _context15.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  templateConfigsDetail: list
                }
              });

            case 9:
              return _context15.abrupt("return", list);

            case 10:
            case "end":
              return _context15.stop();
          }
        }
      }, getTemplateConfigsDetail);
    }),
    // 新增模板管理
    createTemplateConfigs: /*#__PURE__*/_regeneratorRuntime.mark(function createTemplateConfigs(_ref30, _ref31) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function createTemplateConfigs$(_context16) {
        while (1) {
          switch (_context16.prev = _context16.next) {
            case 0:
              payload = _ref30.payload;
              call = _ref31.call;
              _context16.next = 4;
              return call(_createTemplateConfigs, payload);

            case 4:
              res = _context16.sent;
              return _context16.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context16.stop();
          }
        }
      }, createTemplateConfigs);
    }),
    // 更新模板管理
    updateTemplateConfigs: /*#__PURE__*/_regeneratorRuntime.mark(function updateTemplateConfigs(_ref32, _ref33) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function updateTemplateConfigs$(_context17) {
        while (1) {
          switch (_context17.prev = _context17.next) {
            case 0:
              payload = _ref32.payload;
              call = _ref33.call;
              _context17.next = 4;
              return call(_updateTemplateConfigs, payload);

            case 4:
              res = _context17.sent;
              return _context17.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context17.stop();
          }
        }
      }, updateTemplateConfigs);
    }),
    // 删除模板管理
    deleteTemplateConfigs: /*#__PURE__*/_regeneratorRuntime.mark(function deleteTemplateConfigs(_ref34, _ref35) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function deleteTemplateConfigs$(_context18) {
        while (1) {
          switch (_context18.prev = _context18.next) {
            case 0:
              payload = _ref34.payload;
              call = _ref35.call;
              _context18.next = 4;
              return call(_deleteTemplateConfigs, payload);

            case 4:
              res = _context18.sent;
              return _context18.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context18.stop();
          }
        }
      }, deleteTemplateConfigs);
    })
  },
  reducers: {
    updateState: function updateState(state, _ref36) {
      var payload = _ref36.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};